import 'https://cdn.bootcdn.net/ajax/libs/jquery/2.2.0/jquery.js';
class Louti {
    constructor() {
        this.loutinav = $('.elevator');
        // alert('sdadad')
        this.topnav = $('.top-top');
        this.louti = $('.elevator li').not('.last');
        this.louceng = $('.louceng');
        this.gotop = $('.gotop')
        this.gobottom = $('.gobottom')
    }
    init() {
        let _this = this;

        function scroll() {
            let scrolltop = $(window).scrollTop();
            if (scrolltop >= 420) {
                _this.loutinav.show()
                _this.topnav.show()
            } else {
                _this.loutinav.hide()
                _this.topnav.hide()
            }

            _this.louceng.each(function(index, element) {
                let loucengtop = $(element).offset().top + 200;
                if (loucengtop >= scrolltop) {
                    _this.louti.eq(index).addClass('active').siblings().removeClass('active');
                    return false;
                }
            });

        }
        scroll()
        $(window).on('scroll', () => {
            scroll()
        })


        this.louti.on('click', function() {
            $(window).off(); //取消滚轮事件
            let index = $(this).index();
            $(this).addClass('active').siblings().removeClass('active');

            let loucengtop = _this.louceng.eq(index).offset().top;
            $('html').animate({
                scrollTop: loucengtop
            }, function() {
                $(window).on('scroll', () => {
                    scroll();
                });
            });
        });

        // 回顶部
        this.gotop.on('click', function() {
            $('html').animate({
                scrollTop: 0
            });

        });

        this.gobottom.on('click', function() {
            $('html').animate({
                scrollTop: 7900
            });

        });

    }

}
export {
    Louti
}